//
//  GMBubbleView.m
//  SmartTourism
//
//  Created by 许瑞邦 on 2019/6/17.
//

#import "GMBubbleView.h"

#define Arror_height 5

@implementation GMBubbleView

- (instancetype)init{
    if(self = [super init]){
        self.backgroundColor=[UIColor clearColor];
        self.layer.backgroundColor = [UIColor clearColor].CGColor;
    }
    return self;
}

-(void)drawRect:(CGRect)rect{
    self.backgroundColor=[UIColor clearColor];
    self.layer.backgroundColor = [UIColor clearColor].CGColor;
    
    [[UIColor clearColor] setFill];
    UIRectFill(rect);
    
//    UIImage* bgImage = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(180, 50)];
    [self drawInContext:UIGraphicsGetCurrentContext()];
    
//    self.layer.shadowColor = [[UIColor blackColor] CGColor];
//    self.layer.shadowOpacity = 1.0;
//    self.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
}

-(void)drawInContext:(CGContextRef)context
{
    CGContextSetLineWidth(context, 2.0);
    CGContextSetFillColorWithColor(context, [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0].CGColor);
    [self getDrawPath:context];
    CGContextSetShadow(context,CGSizeMake(1.0, 1.0),1.0);
    CGContextFillPath(context);
}

- (void)getDrawPath:(CGContextRef)context
{
    CGRect rrect = self.bounds;
    CGFloat radius = 6.0;
    CGFloat minx = CGRectGetMinX(rrect),
    midx = CGRectGetMidX(rrect),
    maxx = CGRectGetMaxX(rrect);
    CGFloat miny = CGRectGetMinY(rrect),
    // midy = CGRectGetMidY(rrect),
    maxy = CGRectGetMaxY(rrect)-Arror_height;
    CGContextMoveToPoint(context, midx+Arror_height, maxy);
    CGContextAddLineToPoint(context,midx, maxy+Arror_height);
    CGContextAddLineToPoint(context,midx-Arror_height, maxy);
    CGContextAddArcToPoint(context, minx, maxy, minx, miny, radius);
    CGContextAddArcToPoint(context, minx, minx, maxx, miny, radius);
    CGContextAddArcToPoint(context, maxx, miny, maxx, maxx, radius);
    CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
    CGContextClosePath(context);
}




@end
